package com.ruoyi.reception;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.IdWorker;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.receipt.domain.TbKnowledgeList;
import com.ruoyi.receipt.service.ITbKnowledgeListService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 知识点目录管理Controller
 * 
 * @author ruoyi
 * @date 2021-03-27
 */
@RestController
@RequestMapping("/reception/listRec")
public class TbKnowledgeListRecController extends BaseController
{
    @Autowired
    private ITbKnowledgeListService tbKnowledgeListService;

    @Autowired
    private IdWorker idWorker;

    /**
     * 查询知识点目录管理列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TbKnowledgeList tbKnowledgeList)
    {
        startPage();
        List<TbKnowledgeList> list = tbKnowledgeListService.selectTbKnowledgeListList(tbKnowledgeList);
        return getDataTable(list);
    }

    /**
    * 导出知识点目录管理列表
    */
    @Log(title = "知识点目录管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TbKnowledgeList tbKnowledgeList)
    {
        List<TbKnowledgeList> list = tbKnowledgeListService.selectTbKnowledgeListList(tbKnowledgeList);
        ExcelUtil<TbKnowledgeList> util = new ExcelUtil<TbKnowledgeList>(TbKnowledgeList.class);
        return util.exportExcel(list, "list");
    }

    /**
     * 获取知识点目录管理详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        TbKnowledgeList tbKnowledgeList = tbKnowledgeListService.selectTbKnowledgeListById(id);
        return AjaxResult.success(tbKnowledgeList);
    }

    /**
     * 新增知识点目录管理
     */
    @Log(title = "知识点目录管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TbKnowledgeList tbKnowledgeList)
    {
        tbKnowledgeList.setId(idWorker.nextId());
        return toAjax(tbKnowledgeListService.insertTbKnowledgeList(tbKnowledgeList));
    }

    /**
     * 修改知识点目录管理
     */
    @Log(title = "知识点目录管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TbKnowledgeList tbKnowledgeList)
    {
        return toAjax(tbKnowledgeListService.updateTbKnowledgeList(tbKnowledgeList));
    }

    /**
     * 删除知识点目录管理
     */
    @Log(title = "知识点目录管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tbKnowledgeListService.deleteTbKnowledgeListByIds(ids));
    }
}
